package com.jumi.microservice.controller.logistics.admin;

import com.alibaba.excel.EasyExcel;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.dto.logistics.admin.SelfWaitSendRequest;
import com.jumi.microservice.dto.logistics.admin.SelfWaitSendResponse;
import com.jumi.microservice.dto.logistics.excel.SelfWaitSend;
import com.jumi.microservice.service.logistics.admin.SelfWaitSendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author by mazhao
 * @Classname SelfWaitSendController
 * @Description TODO
 * @Date 2020/9/4 14:33
 */
@RestController
@RequestMapping("/admin/logistics")
@Api(tags = "自营待发货")
public class SelfWaitSendController extends BaseController {

    @Resource
    SelfWaitSendService selfWaitSendService;

    @ApiOperation("自营待发货列表")
    @PostMapping("/selfWaitSendList")
    public TableDataInfo<SelfWaitSendResponse> selfWaitSendList(SelfWaitSendRequest request){
        return selfWaitSendService.selfWaitSendList(request);
    }

    @ApiOperation("自营待发货未对接导出")
    @PostMapping("/selfWaitSend/export")
    public void excelExport(HttpServletResponse response,SelfWaitSendRequest request) throws IOException {
        ExportExcelCommonResponse<SelfWaitSend> excelExportExportExcelCommonResponse = selfWaitSendService.excelExport(request,getUid(),getUserName());
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename="+ excelExportExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(),SelfWaitSend.class).sheet("sheet1").doWrite(excelExportExportExcelCommonResponse.getData());
    }

    @ApiOperation("自营待发货导入")
    @PostMapping("/selfWaitSend/import")
    public ResponseResult<List<String>> selfWaitSendImport(HttpServletRequest request) throws IOException {
        Long uid = getUid();
        String name = getUserName();
        return success(selfWaitSendService.excelImport(request,uid,name));
    }

}
